<template>
    <div class="remainMoney">
        <!--顶部-->
        <van-nav-bar
                :border="false"
                title="余额"
                right-text="余额明细"
                left-arrow
                @click-left="toBack"
                @click-right="balanceBtn">
        </van-nav-bar>
        <div class="remainHeader text-center-pk bg-D82D11 page-pad-pk list-item-pad-pk d-flex-pk text-white-pk">
            <div>
                <div class="font-size-14-pk">我的余额(元)</div>
                <div class="font-size-18-pk">{{userInfo.money}}</div>
            </div>
            <div>
                <div class="font-size-14-pk">可用余额(元)</div>
                <div class="font-size-18-pk">{{remainMoney}}</div>
            </div>
            <div>
                <div class="font-size-14-pk">冻结余额(元)</div>
                <div class="font-size-18-pk">{{userInfo.freeMoney}}</div>
            </div>
        </div>
        <div class="rechargeMoney">
            <van-cell is-link to="recharge">
                <template slot="title">
                    <img src="../../assets/images/rechargeMoneyIcon.png" alt="iconImg" class="iconImg">
                    <span class="text-color-gray font-size-15-pk text-black-pk">充值</span>
                </template>
            </van-cell>
        </div>
        <div class="rechargeMoney">
            <van-cell is-link to="withdraw">
                <!-- 使用 title 插槽来自定义标题 -->
                <template slot="title">
                    <img src="../../assets/images/withdrawMoneyIcon.png" alt="iconImg" class="iconImg">
                    <span class="text-color-gray font-size-15-pk text-black-pk">提现</span>
                </template>
            </van-cell>
        </div>
    </div>
</template>
<script>
    export default {
        name:"remainMoney",
        title:"余额",
        data(){
            return{
                userInfo:{},
                remainMoney:""
            }
        },
       /* beforeRouteEnter(to, from, next) {
            let prePath = "";
            //待优化，将参数带上
            if(from.path === "/login" || from.path === "/register" || from.path === "/" || from.path === "/wxLogin" ) {
                prePath = "/index"
            }else {
                //涉及到需要保存上一页数据的，可以拼接到地址
                prePath = from.fullPath
            }
            next( vm => {
                vm.$store.commit("setPrePath", prePath)
            })
        },*/
        created() {
            this.getUserInfo();
        },
        methods:{
            toBack(){
              this.$router.push({
                  name:"personalCenter"
              })
            },
            //获取用户信息
            getUserInfo(){
                this.$api.getUserInfo('1').then(res=>{
                    let result=this.$resData(res);
                    if(result){
                        this.userInfo=result;
                        this.remainMoney= (Math.pow(10,3)*this.userInfo.money - Math.pow(10,3)*this.userInfo.freeMoney)/Math.pow(10,3);
                    }
                })
            },
            //余额明细
            balanceBtn(){
                this.$router.push({
                    name:"remainList"
                })
            }
        }
    }
</script>
<style lang="scss" scoped>
    .remainMoney{
        line-height: 1.6;
        .remainHeader{
            justify-content: space-between;
        }
        .rechargeMoney{
            .iconImg{
                width: 28px;
                height: 28px;
                padding-right: 10px;
            }

        }
    }

</style>
